package application;

import ij.process.ImageProcessor;

public class LocalisationColor {

	public static ImageProcessor run(ImageProcessor image) {
		ImageProcessor result = image.createProcessor(image.getWidth(), image.getHeight());
		
		int[] iArrayp1 = {0,0,0};
		int[] iArrayp2 = {0,0,0};
		
		for(int i=1;i<image.getHeight()-1;i++)
			for(int j=1;j<image.getWidth()-1;j++)
			{
				image.getPixel(j, i, iArrayp1);
				image.getPixel(j+1, i, iArrayp2);
				//Verfie si deux pixels voisin sont de couleur proche
				if((iArrayp1[0] == iArrayp2[0] || iArrayp1[0] == iArrayp2[0]+1 || iArrayp1[0] == iArrayp2[0]-1 || iArrayp1[0] == iArrayp2[0]+2 || iArrayp1[0] == iArrayp2[0]-2 || iArrayp1[0] == iArrayp2[0]+3 || iArrayp1[0] == iArrayp2[0]-3)
				&& (iArrayp1[1] == iArrayp2[1] || iArrayp1[1] == iArrayp2[1]+1 || iArrayp1[1] == iArrayp2[1]-1 || iArrayp1[1] == iArrayp2[1]+2 || iArrayp1[1] == iArrayp2[1]-2 || iArrayp1[1] == iArrayp2[1]+3 || iArrayp1[1] == iArrayp2[1]-3)
				&& (iArrayp1[2] == iArrayp2[2] || iArrayp1[2] == iArrayp2[2]+1 || iArrayp1[2] == iArrayp2[2]-1 || iArrayp1[2] == iArrayp2[2]+2 || iArrayp1[2] == iArrayp2[2]-2 || iArrayp1[2] == iArrayp2[2]+3 || iArrayp1[2] == iArrayp2[2]-3))
				{
					result.putPixel(j, i, iArrayp1);
					result.putPixel(j+1, i, iArrayp1);
				}
			}
					
		return result;
	}

}
